import TableData from "@/components/public/el-table"; //主页面列表
import actions from "@/actions";
import messageBox from "@/components/public/messageBox"; //主页面分页

import TableLyout from '@/components/commonPublic/tableLyout.vue'
import CustomDialog from "@/components/machineNetworkManage/pressDataMonitor/index.vue";

import {
    getTestHntFlexuralList, //列表页接口
    getBaseDataitemDetailByItemCode, //数据
} from "@/api/request.js";
import formJs from "./regexDetail.js"; //新增弹框配置
import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form

export default {
    name: "pressDataMonitor",
    data() {
        return {
            name: "pressDataMonitor",
            userNature: null, //用户Nature
            showMsgBox: false,
            msgTip: "请先选中数据行！",
            msgType: 1,
            projectsObj: [], //项目名
            tendersObj: [],
            falgId: null,
            isLock: false,
            tableTitle:"水泥混凝土抗压强度原始采集数据记录",

            isLock: false,
            projectId: null,
            projectName: null,
            loading: false,
            btnObj: formJs.btnObj, //按钮
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            radio: "待办",
            // 列表
            getList: {
                fprojectid: "",
                fCompanyid: "", // 左侧选中组织机构id
                keyType: "抗压强度", // 上方查询条件试验类型
                keyWord: "", //上方查询条件样品编号/工程名称
                MachineId: "", //上方查询条件设备编号
                fAge: "", //上方查询条件龄期
                fStrength: "", //上方查询条件强度等级
                fCloseoperation: "", //上方查询条件闭合状态
                modelType: "0", // 0-正常 1-不合格
                page: 1, // 当前页码
                pageSize:15, // 每页显示条数
                userId: "", //用户id
                fCementtype:"",

                startDates: "", //开始时间
                endDates: "", //结束时间
                timeDates: "",
            },
            isShow: false, //是否显示弹框
            statusNum: null, //点击那个按钮
            dataFid: null, //列表详情id
            currentRow: null, //列表详情
            activeIndex: "1",
            fId: null, //当前数据fId
            tableData: [],
            companyId: null,
            currentRowId: "",
            dialogTitle: null,
            

        };
    },
    components: {
        TableLyout,
        publicForm,
        TableData,
        messageBox,
        CustomDialog
    },
    mounted() {
        actions.onGlobalStateChange((state, prev) => {
            this.userInfo = prev.currentUser
        }, true);

        this.getDate()
        this.getBaseDataitemDetailByItemCode('StrengthGrade1', 2) //设计强度等级(Qdlevel)
  

    },
    methods: {
        confirmMsg() {
            this.showMsgBox = false;
        },
        reset(e) {
            this.getList = this.$options.data.call(this).getList
            this.getList.fprojectid = e
        },
        // 选择项目名称
        selectCompany(e) {
            this.companyName = e.F_ProjectName;
            this.getList.fDepartmentid = e.F_ProjectId;
            this.projectName = "";
            this.getList.fCompanyid = "";
           

            this.yj_searchForm(this.getList);
        },
        // 选择施工单位
        selectProject(e) {

            this.projectName = e.F_CompanyName;
            this.getList.fCompanyid = e.F_CompanyId;
            // this.yj_searchForm(this.getList);
        },
        async getTender(e) {
            await this.$http(
                " http://172.18.5.31:8300/IOTManagement/Base/Company/getGXJLBaseCompanyList.do?projectId=" +
                e, {
                    headers: {
                        "Content-Type": "application/json",
                        Authorization: localStorage.getItem("access_token"),
                    },
                }
            ).then((res) => {
                if (res.status == 200) {
                    var data = res.data.data.GXCompanyList;
                    this.tendersObj = [];
                    if (data.length == 0) {
                        this.$message.warning({
                            content: "有其他人员登录此账号！",
                            duration: 1000,
                        });
                        setTimeout(() => {
                            window.location.href = "http://172.18.5.201:1080/login";
                        }, 1200);
                    } else     if (data.length == 1) {
                        data.map((item) => {
                            this.tendersObj.push({
                                fItemName: item.sectionName,
                                fItemValue: item.sectionId,
                            });
                        });
                        this.getList.fCompanyid = data[0].sectionId;
                    } else {
                        this.tendersObj = [{
                            fItemName: "所有标段",
                            fItemValue: "",
                        }, ];
                        data.map((item) => {
                            this.tendersObj.push({
                                fItemName: item.sectionName,
                                fItemValue: item.sectionId,
                            });
                        });
                    }
                }
            });
        },
        selectTender(e) {
            this.getList.stationId = "";
            this.getList.machineId = "";
            this.bhzDataList = [];
            this.bhjDataList = [];
            this.mixingPlantList(0, this.getList);
        },
        closeDialog() {
            this.isShow = false;
        },
        getBtnName(name, status) {
            this.statusNum = status
            this.yj_edit(status)
        },

        // 新增/编辑
        yj_edit(num) {
           if (num == 7) { //查看

                if (this.dataFid != null) {
                    this.statusNum = 7
                    this.isShow = true;
                    this.editText();


                } else {
                    this.$message.warning({
                        content:"请先选择需要查看的数据",
                        duration: 1000
                    });
      
                }
            }

        },
        editText() {
            this.isShow = true;
        },
        // 查看
        // 点击查看
        yj_viewForm(row, label) {
            if (label == "样品编号") {
                this.currentRow = row;
                this.statusNum = 7
                this.isShow = true;
            }
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val
            this.dataFid = val.fId;
        },
        // 数据字典
        getBaseDataitemDetailByItemCode(status) {
            this.searchObj[4].options = []
            getBaseDataitemDetailByItemCode({
                fItemcode: status
            }).then(res => {
                var data = res.data.baseDataitemdetailList
                var arr = [{
                    value: "",
                    label: "强度等级"
                }]
                data.map(item => {
                    arr.push({
                        value: item.fItemvalue,
                        label: item.fItemvalue
                    })
                })
                this.searchObj[4].options = arr

            })
        },
        // 获取列表数据
        // 获取列表数据
        yj_searchForm(data) {
            if (data.keyType == '芯样强度') {
                this.tableTitle = "水泥混凝土芯样强度原始采集数据记录";
            } else if (data.keyType == '抗折强度') {
                this.tableTitle = "水泥混凝土抗折强度原始采集数据记录";
            } else if (data.keyType == '抗折强度') {
                this.tableTitle = "水泥混凝土抗压强度原始采集数据记录";
            }
            window.sessionStorage.setItem(
                "GxEmbedded-machineNetworkManage_getList",
                JSON.stringify(data)
            );
            var id;
            if (data.fCompanyid != "") {
                id = data.fCompanyid;
            } else {
                id = data.fprojectid;
            }
            var obj = {
                // fCompanyid: "d486cef5-67ad-42ae-bf7f-d3a104760bd2",
                // userId: "3a34a5db-5cbb-42c7-87a9-619321768c53",
                fCompanyid: id, // 左侧选中组织机构id
                keyType: data.keyType, // 上方查询条件试验类型
                keyWord: data.keyWord, //上方查询条件样品编号/工程名称
                MachineId: data.MachineId, //上方查询条件设备编号
                fAge: data.fAge, //上方查询条件龄期
                fStrength: data.fStrength, //上方查询条件强度等级
                fCloseoperation: data.fCloseoperation, //上方查询条件闭合状态
                modelType: "0", // 0-正常 1-不合格
                page: data.page, // 当前页码
                pageSize: data.pageSize, // 每页显示条数
                userId: this.userInfo.id, //用户id
                startDates: data.startDates, //开始时间
                fCementtype:"",
                
                endDates: data.endDates //结束时间
            }
            this.loading = true;
            var that = this;
            getTestHntFlexuralList(obj)
                .then((res) => {
                    console.log(res);
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error({
                            content:"列表数据获取失败"+res.msg,
                            duration: 1000
                        });
    
                      
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error({
                        content:"列表数据获取失败"+res.msg,
                        duration: 1000
                    });
                    this.loading = false;
                });
        },

        selectTime(e) {
            console.log(77, e);
            if (e[0] != "" && e[1] != "") {
                this.getList.startDates = e[0]; // 开始时间
                this.getList.endDates = e[1]; // 截至时间
            } else {
                this.getList.startDates = ""; // 开始时间
                this.getList.endDates = ""; // 截至时间
            }
            this.getList.timeDates = [e[0], e[1]]

            this.yj_searchForm(this.getList);

        },
        getDate() {
           

            if (JSON.parse(sessionStorage.getItem("GxEmbedded-machineNetworkManage_getList"))) {
                var data = JSON.parse(sessionStorage.getItem("GxEmbedded-machineNetworkManage_getList"));
                // this.getList.timeDates = [data.startDates, data.endDates]
                if (data.fprojectid != "") {
                    this.getTender(data.fprojectid);
                } else {
                    data.fprojectid = this.projectsObj[1].fItemValue;
                    this.getTender(data.fprojectid);
                }
                this.getList = {
                    fprojectid: data.fprojectid,
                    fCompanyid: data.fCompanyid, //左侧选中组织机构id
                    keyType: "抗压强度", //上方查询条件材料种类
                    keyWord: data.keyWord, //上方查询条件样品编号/工程名称
                    MachineId: data.MachineId, //上方查询条件设备编号
                    fAge: data.fAge, //上方查询条件龄期
                    fStrength: "", //上方查询条件强度等级
                    fCloseoperation: data.fCloseoperation, //上方查询条件闭合状态
                    modelType: 0, // 0-正常 1-不合格
                    page: 1, //当前页码
                    pageSize: 15, //每页显示条数
                    userId: this.userInfo.id, //查询待办或已办时传 列表页查询不传
                    startDates: data.startDates, //进场开始时间
                    endDates: data.endDates, //进场结束时间
                    timeDates: [data.startDates, data.endDates]
                };


            } else {
                this.getList.startDates = this.common.getDay(-90); // 开始时间
                this.getList.endDates = this.common.getDay(0); // 截至时间
                this.getList.timeDates = [this.getList.startDates, this.getList.endDates]
                this.getList.keyType = "抗压强度"

            }

            // this.yj_searchForm(this.getList);
        },


    },
};